{% extends "base.html" %}

{% block content %}

<script language=javascript>

function verify(form){
  if(form.name.value==""){
	alert("Enter the name please!");
	form.name.focus();		
       return false;
	}
	{% if not salesperson.id %}
	 if(form.password.value==""){
	alert("Enter password please");
	form.password.focus();		
       return false;
	}
	 if(form.password2.value==""){
	alert("Enter the confirm password please");
	form.password2.focus();		
       return false;
	}
	 if(form.password.value!=form.password2.value){
	  alert("The confirm password is not the same with password");
       return false;
	}
{% endif %}
  if(form.truename.value==""){
	alert("Enter the truename please!");
	form.truename.focus();		
       return false;
	}
  if(form.tel.value==""){
	alert("Enter the tel please!");
	form.tel.focus();		
       return false;
	}
  if(form.mobile.value==""){
	alert("Enter the mobile please!");
	form.mobile.focus();		
       return false;
	}
  if(form.email.value==""){
	alert("Enter the email please!");
	form.email.focus();		
       return false;
	}
 if(form.level.value==""){
	alert("Choose level please");
	form.level.focus();		
       return false;
	}

return true;
 }

</script>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">
<form name='form1' id='form1' action="/savesales/" method='post' onsubmit='return verify(this);'>
<table width='650' class='grid' cellspacing='1' align='center'><tr><td colspan='2' class='title'>Add/Edit user</td></tr>
<tr valign='middle' align='left'></tr>

<tr valign='middle' align='left'><td class='odd' width='25%'><font color="red">*</font>Name:</td>
<td class='even'><input type="text" name="name" value="{{salesperson.name}}" /></td></tr>
{% if not salesperson.id %}
<tr valign='middle' align='left'><td class='odd' width='25%'><font color="red">*</font>Password:</td>
<td class='even'><input type="password" name="password" /></td></tr>

<tr valign='middle' align='left'><td class='odd' width='25%'><font color="red">*</font>Password again:</td>
<td class='even'><input type="password" name="password2" /></td></tr>
{% endif %}
<tr valign='middle' align='left'><td class='odd' width='25%'><font color="red">*</font>True Name:</td>
<td class='even'><input type="text" name="truename" value="{{salesperson.truename}}"/></td></tr>
<tr valign='middle' align='left'><td class='odd' width='25%'><font color="red">*</font>Tel:</td>
<td class='even'><input type="text" name="tel"  value="{{salesperson.tel}}"/></td></tr>
<tr valign='middle' align='left'><td class='odd' width='25%'><font color="red">*</font>Mobile:</td>
<td class='even'><input type="text" name="mobile"  value="{{salesperson.mobile}}"/><input type="checkbox" name="sendsms" value="1" {%if salesperson.sendsms%}checked{%endif%}/>send sms</td></tr>
<tr valign='middle' align='left'><td class='odd' width='25%'><font color="red">*</font>Email:</td>
<td class='even'><input type="text" name="email"  value="{{salesperson.email}}"/></td></tr>
<tr valign='middle' align='left'><td class='odd' width='25%'><font color="red">*</font>Level</td>
<td class='even'><select name="level">
	<option value="">Choose Level plz</option>
	
{% for role in roles %}  

	<option value="{{role.name}}" {% ifequal salesperson.level role.name %}selected{% endifequal %}> {{role.name}}</option> 

{% endfor %}
<!--<option value="superadmin" {% ifequal salesperson.level "superadmin" %}selected{% endifequal %}> superadmin</option>-->
</select>
</td></tr>
 <!-- huangzy edit begin  user group-->
<tr valign='middle' align='left'><td class='odd' width='25%'><font color="red">*</font>Group</td>
<td class='even'>
<select name="group">
	<option value="0">Choose Sales Group</option>
{% for item in salesgroup %}  

	<option value="{{item.id}}" {% ifequal salesperson.group item.id %}selected{% endifequal %}> {{item.name}}</option> 

{% endfor %}
	
</select>
</td></tr>
 <!--   huangzy edit end-->
{% if salesperson.id %}
<input type="hidden" name="id" value="{{salesperson.id}}" />
{% endif %}
<tr valign='middle' align='left'><td class='odd' width='25%'></td>
<td class='even'>&nbsp;<input type='submit' class='button' name='submit'  id='submit' value=' Submit '  />&nbsp;&nbsp;{% if not salesperson.id %}<input type='reset' class='button' name='reset'  id='reset' value=' Reset ' />{% endif%}{% if salesperson.id %}<input type='button' class='button' name='back'  id='reset' value=' Back ' onclick="javascrip:history.back(1)" />{%endif%}</form></td></tr>
{% if errormsg %}
<tr valign='middle' align='left'><td class='odd' width='25%'><font color="red">Error infomation</font></td>
<td class='even'><font color="red">{{errormsg}}</font></td></tr>
{% endif %}
</table>

{% endblock %}

